import pandas as pd
from sklearn import linear_model
from sklearn import cross_validation
from sklearn import svm
from sklearn.ensemble import RandomForestRegressor


# 读入原始数据并处理时间
dataSet = pd.read_csv("../process_data/data/kaggle_bike_processed.csv", header = 0) #读入数据

# 得到训练数据和目标值
target = dataSet['count'].values
data = dataSet.drop(['count'], axis=1).values
print(data.shape)
print(target.shape)


# 使用pca降维后的数据
df_pca_data = pd.read_csv("data/pca_dimention_reducted.csv", header=None)
pca_data = df_pca_data.values
print(pca_data.shape)


# 使用lda降维后的数据
df_lda_data = pd.read_csv('data/lda_dimention_reducted.csv', header=None)
lda_data = df_lda_data.values
print(lda_data.shape)


# 使用lle降维后的数据
df_lle_data = pd.read_csv('data/lle_dimention_reducted.csv', header=None)
lle_data = df_lle_data.values
print(lle_data.shape)


# 使用isomap降维后的数据
df_isomap_data = pd.read_csv('data/isomap_dimention_reducted.csv', header=None)
isomap_data = df_isomap_data.values
print(isomap_data.shape)

# 切分一下数据（训练集和测试集）
cv = cross_validation.ShuffleSplit(len(data), n_iter=3, test_size=0.2,
    random_state=0)


# 各种模型来一圈
print("线性回归")
for train, test in cv:
    print("原始数据回归        PCA降维数据回归        LDA降维数据回归        LLE降维数据回归"
          "        ISOMAP降维数据回归")
    svc = linear_model.LinearRegression().fit(data[train], target[train])
    pca_svc = linear_model.LinearRegression().fit(pca_data[train], target[train])
    lda_svc = linear_model.LinearRegression().fit(lda_data[train], target[train])
    lle_svc = linear_model.LinearRegression().fit(lle_data[train], target[train])
    isomap_svc = linear_model.LinearRegression().fit(isomap_data[train], target[train])
    print("origin score: {0:.3f}, PCA score: {1:.3f},    LDA score: {2:.3f},    LLE score: {3:.3f}"
          ",    ISOMAP score: {4:.3f}\n".format(
        svc.score(data[test], target[test]), pca_svc.score(pca_data[test], target[test]),
        lda_svc.score(lda_data[test], target[test]), lle_svc.score(lle_data[test], target[test]),
        isomap_svc.score(isomap_data[test], target[test])))



'''
print("岭回归")
for train, test in cv:
    svc = linear_model.Ridge().fit(data[train], target[train])
    print("train score: {0:.3f}, test score: {1:.3f}\n".format(
        svc.score(data[train],target[train]), svc.score(data[test], target[test])))

print("支持向量回归/SVR(kernel='rbf',C=10,gamma=.001)")
for train, test in cv:

    svc = svm.SVR(kernel ='rbf', C = 10, gamma = .001).fit(data[train], target[train])
    print("train score: {0:.3f}, test score: {1:.3f}\n".format(
        svc.score(data[train], target[train]), svc.score(data[test], target[test])))
'''

print("随机森林回归/Random Forest(n_estimators = 100)")
for train, test in cv:
    print("原始数据回归        PCA降维数据回归        LDA降维数据回归")
    svc = RandomForestRegressor(n_estimators = 100).fit(data[train], target[train])
    pca_svc = RandomForestRegressor(n_estimators = 100).fit(pca_data[train], target[train])
    lda_svc = RandomForestRegressor(n_estimators = 100).fit(lda_data[train], target[train])
    lle_svc = RandomForestRegressor(n_estimators = 100).fit(lle_data[train], target[train])
    isomap_svc = RandomForestRegressor(n_estimators = 100).fit(isomap_data[train], target[train])
    print("origin score: {0:.3f}, PCA score: {1:.3f},    LDA score: {2:.3f},    LLE score: {3:.3f}"
          ",    ISOMAP score: {4:.3f}\n".format(
        svc.score(data[test], target[test]), pca_svc.score(pca_data[test], target[test]),
        lda_svc.score(lda_data[test], target[test]), lle_svc.score(lle_data[test], target[test]),
        isomap_svc.score(isomap_data[test], target[test])))


